//
/**
 * Filename: fig10-2_simple_signal.c
 * Author:   csbonkers
 * Contact:  forever65535@qq.com
 * Date:     2021/6/2
 * Description:
 *    
 */
#include "apue.h"
static void sig_usr(int signo); /* one signal for both signals*/

int main(int argc, char *argv[]) {
  if (signal(SIGUSR1, sig_usr) == SIG_ERR) {
    err_sys("can't catch SIGUSR1");
  }
  if (signal(SIGUSR2, sig_usr) == SIG_ERR) {
    err_sys("can't catch SIGUSR1");
  }
  printf("current process identifier is %ld\n", (long) getpid());
  for (;;) {
    pause();
  }
}

void sig_usr(int signo) {
  switch (signo) {
    case SIGUSR1:
      printf("received SIGUSR1\n");
      break;
    case SIGUSR2:
      printf("received SIGUSR2\n");
      break;
    default:
      err_dump("received signal %d\n", signo);
  }
}